package com.eightywork.life.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.FrameLayout;

public class ActionsLayout extends FrameLayout {

  private final Paint mFadePaint = new Paint();

  private int mFadeFactor = 0;

  public ActionsLayout(Context context) {
    this(context, null);
  }

  public ActionsLayout(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
  }

  public ActionsLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
  }

  public void invalidate(int fadeFactor) {
    mFadeFactor = fadeFactor;
    invalidate();
  }

  @Override
  protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);

    if (mFadeFactor > 0f) {
      mFadePaint.setColor(Color.argb(mFadeFactor, 0, 0, 0));
      canvas.drawRect(0, 0, getWidth(), getHeight(), mFadePaint);
    }
  }
}
